🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / ui / src / commonMain / kotlin / org / meshtastic / core / ui / util / LocalEventBranding.kt
Displaying Raw • Download
core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/util/LocalEventBranding.kt c2a8e67aee4db8f77b7dc6924dcebfbdfba1bf5e (c2a8e67a) Text, 4.92 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.util
Tff7b72import T7ee787androidx.compose.foundation.Image
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.compositionLocalOf
Tff7b72import T7ee787androidx.compose.ui.Modifier
Tff7b72import T7ee787androidx.compose.ui.graphics.Color
Tff7b72import T7ee787androidx.compose.ui.graphics.vector.rememberVectorPainter
Tff7b72import T7ee787androidx.compose.ui.layout.ContentScale
Tff7b72import T7ee787coil3.compose.AsyncImage
Tff7b72import T7ee787kotlinx.datetime.LocalDate
Tff7b72import T7ee787kotlinx.datetime.TimeZone
Tff7b72import T7ee787kotlinx.datetime.todayIn
Tff7b72import T7ee787org.jetbrains.compose.resources.DrawableResource
Tff7b72import T7ee787org.jetbrains.compose.resources.painterResource
Tff7b72import T7ee787org.jetbrains.compose.resources.vectorResource
Tff7b72import T7ee787org.meshtastic.core.model.EventFirmwareEdition
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.ic_meshtastic
Tff7b72import T7ee787org.meshtastic.core.resources.img_event_hamvention
Tff7b72import T7ee787kotlin.time.Clock
T8b949e/**
* Provides the active [EventFirmwareEdition] (if any) to the composition tree. When a connected device reports an event
* firmware edition, this local is populated at the app root so that
* [MainAppBar][org.meshtastic.core.ui.component.MainAppBar] can display event branding automatically — no per-screen
* wiring needed.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffCompositionLocalAllowlistTa5d6ff"Tb4b4b4)
Tff7b72val Te6edf3LocalEventBranding Tff7b72= Te6edf3compositionLocalOfTff7b72<Te6edf3EventFirmwareEdition?Tff7b72> Tb4b4b4{ Tff7b72null Tb4b4b4}
T8b949e/**
* Bundled branding drawable for an edition, or `null`. Used as the offline fallback by [EventBrandingIcon] when a
* hosted [EventFirmwareEdition.iconUrl] is absent or fails to load.
*/
Tff7b72fun Td2a8ffeventIconForTb4b4b4(Te6edf3editionNameTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3DrawableResource? Tff7b72= Tff7b72when Tb4b4b4(Te6edf3editionNameTb4b4b4) Tb4b4b4{
Ta5d6ff"Ta5d6ffHAMVENTIONTa5d6ff" Tff7b72-Tff7b72> Te6edf3ResTb4b4b4.Te6edf3drawableTb4b4b4.Te6edf3img_event_hamvention
Tff7b72else Tff7b72-Tff7b72> Tff7b72null
Tb4b4b4}
T8b949e/**
* Event branding icon: loads the hosted [EventFirmwareEdition.iconUrl] when present, falling back to the bundled
* per-edition drawable ([eventIconFor]), and finally the Meshtastic logo. The fallback painter also backs Coil's
* loading/error states so there is never an empty slot.
*/
Tf0883e@Composable
Tff7b72fun Td2a8ffEventBrandingIconTb4b4b4(
Te6edf3editionTb4b4b4: Te6edf3EventFirmwareEditionTb4b4b4,
Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4,
Te6edf3contentDescriptionTb4b4b4: Tffa657String? Tff7b72= Te6edf3editionTb4b4b4.Te6edf3displayNameTb4b4b4,
Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3bundled Tff7b72= Te6edf3eventIconForTb4b4b4(Te6edf3editionTb4b4b4.Te6edf3editionTb4b4b4)
Tff7b72val Te6edf3fallback Tff7b72=
Te6edf3bundledTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3painterResourceTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4} Tff7b72?: Te6edf3rememberVectorPainterTb4b4b4(Te6edf3vectorResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3drawableTb4b4b4.Te6edf3ic_meshtasticTb4b4b4)Tb4b4b4)
Tff7b72val Te6edf3url Tff7b72= Te6edf3editionTb4b4b4.Te6edf3iconUrl
Tff7b72if Tb4b4b4(Te6edf3urlTb4b4b4.Te6edf3isNullOrBlankTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3ImageTb4b4b4(
Te6edf3painter Tff7b72= Te6edf3fallbackTb4b4b4,
Te6edf3contentDescription Tff7b72= Te6edf3contentDescriptionTb4b4b4,
Te6edf3contentScale Tff7b72= Te6edf3ContentScaleTb4b4b4.Te6edf3FitTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4,
Tb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3AsyncImageTb4b4b4(
Te6edf3model Tff7b72= Te6edf3urlTb4b4b4,
Te6edf3contentDescription Tff7b72= Te6edf3contentDescriptionTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4,
Te6edf3contentScale Tff7b72= Te6edf3ContentScaleTb4b4b4.Te6edf3FitTb4b4b4,
Te6edf3placeholder Tff7b72= Te6edf3fallbackTb4b4b4,
Te6edf3error Tff7b72= Te6edf3fallbackTb4b4b4,
Te6edf3fallback Tff7b72= Te6edf3fallbackTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
T8b949e/**
* Whether the event's last day is in the past, evaluated in the event's own [timeZone][EventFirmwareEdition.timeZone]
* (falling back to the device time zone). Used to nudge users off event firmware once the event is over. Returns
* `false` when [eventEnd][EventFirmwareEdition.eventEnd] is absent or unparseable — an unknown end date is never
* treated as ended.
*/
Tff7b72fun Te6edf3EventFirmwareEditionTb4b4b4.Td2a8ffhasEndedTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tb4b4b4{
Tff7b72val Te6edf3end Tff7b72= Te6edf3eventEndTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3runCatching Tb4b4b4{ Te6edf3LocalDateTb4b4b4.Te6edf3parseTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}Tb4b4b4.Te6edf3getOrNullTb4b4b4(Tb4b4b4) Tb4b4b4} Tff7b72?: Tff7b72return Tff7b72false
Tff7b72val Te6edf3zone Tff7b72= Te6edf3timeZoneTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3runCatching Tb4b4b4{ Te6edf3TimeZoneTb4b4b4.Te6edf3ofTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}Tb4b4b4.Te6edf3getOrNullTb4b4b4(Tb4b4b4) Tb4b4b4} Tff7b72?: Te6edf3TimeZoneTb4b4b4.Te6edf3currentSystemDefaultTb4b4b4(Tb4b4b4)
Tff7b72return Te6edf3ClockTb4b4b4.Te6edf3SystemTb4b4b4.Te6edf3todayInTb4b4b4(Te6edf3zoneTb4b4b4) Tff7b72> Te6edf3end
Tb4b4b4}
T8b949e/** Parses the edition's `#RRGGBB` [EventFirmwareEdition.accentColor] into a [Color], or `null` if absent/malformed. */
Tff7b72fun Te6edf3EventFirmwareEditionTb4b4b4.Td2a8ffaccentColorOrNullTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3Color? Tb4b4b4{
Tff7b72val Te6edf3rgb Tff7b72=
Te6edf3accentColorTff7b72?.Te6edf3trimTb4b4b4(Tb4b4b4)Tff7b72?.Te6edf3removePrefixTb4b4b4(Ta5d6ff"Ta5d6ff#Ta5d6ff"Tb4b4b4)Tff7b72?.Te6edf3takeIf Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3length Tff7b72=Tff7b72= Te6edf3RGB_HEX_LENGTH Tb4b4b4}Tff7b72?.Te6edf3toIntOrNullTb4b4b4(Te6edf3HEX_RADIXTb4b4b4)
Tff7b72?: Tff7b72return Tff7b72null
Tff7b72return Te6edf3ColorTb4b4b4(
Te6edf3red Tff7b72= Tb4b4b4(Te6edf3rgb Te6edf3shr Te6edf3RED_SHIFTTb4b4b4) Te6edf3and Te6edf3BYTE_MASKTb4b4b4,
Te6edf3green Tff7b72= Tb4b4b4(Te6edf3rgb Te6edf3shr Te6edf3GREEN_SHIFTTb4b4b4) Te6edf3and Te6edf3BYTE_MASKTb4b4b4,
Te6edf3blue Tff7b72= Te6edf3rgb Te6edf3and Te6edf3BYTE_MASKTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tff7b72private Tff7b72const Tff7b72val Te6edf3RGB_HEX_LENGTH Tff7b72= T79c0ff6
Tff7b72private Tff7b72const Tff7b72val Te6edf3HEX_RADIX Tff7b72= T79c0ff1T79c0ff6
Tff7b72private Tff7b72const Tff7b72val Te6edf3RED_SHIFT Tff7b72= T79c0ff1T79c0ff6
Tff7b72private Tff7b72const Tff7b72val Te6edf3GREEN_SHIFT Tff7b72= T79c0ff8
Tff7b72private Tff7b72const Tff7b72val Te6edf3BYTE_MASK Tff7b72= T79c0ff0Te6edf3xFF
Served by rngit 1.5.0 - Generated in 0.06s